﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using WinFormsUI.Docking;
using XPTable.Models;
using XPTable.Editors;

namespace ChaSQLite.SubForm
{
    public partial class TableWizardViewer : DockContent
    {
        public TableWizardViewer()
        {
            InitializeComponent();
        }

        private void TableWizardViewer_Load(object sender, EventArgs e)
        {
            this.table.BeginUpdate();
            table.FullRowSelect = true;
            table.Font = new System.Drawing.Font("맑은 고딕", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(129)));

            TextColumn nameColumn = new TextColumn("이름", 300);
            ComboBoxColumn typeColumn = new ComboBoxColumn("유형", 150);
            TextColumn sizeColumn = new TextColumn("크기", 80);
            CheckBoxColumn nullColumn = new CheckBoxColumn("NOT NULL", 80);
            TextColumn defaultColumn = new TextColumn("기본값", 80);

            this.table.ColumnModel = new ColumnModel(new Column[] { nameColumn, typeColumn, sizeColumn, nullColumn, defaultColumn });

            this.table.TableModel = new TableModel();

            this.table.TableModel.RowHeight = 21;
            this.table.BeginEditing += new XPTable.Events.CellEditEventHandler(table_BeginEditing);
            this.table.EndUpdate();
        }

        private void table_BeginEditing(object sender, XPTable.Events.CellEditEventArgs e)
        {
            if (e.Editor is ComboBoxCellEditor)
            {
                //if (e.Column == 3) //MarkerStyle.Circle, MarkerStyle.Cross, MarkerStyle.Diamond, MarkerStyle.Square, MarkerStyle.Triangle
                {
                    ((ComboBoxCellEditor)e.Editor).Items.Clear();
                    ((ComboBoxCellEditor)e.Editor).Items.AddRange(new string[] { 
                                                    "INTEGER", "DOUBLE", "FLOAT", "REAL", "CHAR",
                                                    "TEXT", "VARCHAR", "BLOB", "NUMERIC", "DATETIME" });
                }
            }
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {        
            Row row = new Row(new Cell[] { new Cell(""), 
                                                     new Cell("INTEGER"), 
                                                     new Cell(""),
                                                     new Cell(""),
                                                     new Cell("")});

            int nIntex = table.TableModel.Rows.Add(row);
            table.HideSelection = true;
            table.GridLines = GridLines.Rows;            
        }

        private void btnDel_Click(object sender, EventArgs e)
        {

        }

        private void btnApply_Click(object sender, EventArgs e)
        {

        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnScript_Click(object sender, EventArgs e)
        {

        }
    }
}
